/***************************************************************************
 *   Copyright (C) 2008 by Jesse Crossen   *
 *   jesse.crossen@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef MUSIC_H
#define MUSIC_H

#include "math.h"

#include <QObject>
#include <QList>
#include <QStringList>
#include <QComboBox>
#include <QFile>
#include <QXmlStreamReader>

/**
	@author Jesse Crossen <jesse.crossen@gmail.com>
*/
class Music : public QObject
{
Q_OBJECT
public:
  Music(QObject *parent = 0);

  ~Music();
  
  // the note names of the 12 tone scale
  QStringList NoteNames;
  
  // the frequencies for the complete piano scale
  QList<float> Frequencies;

  // convert a note name into a scale index
  int Note(const char * name);
  // convert a scale index into a note name
  QString NoteName(int index);
  
  // instruments
  struct Instrument {
    QString name;
    QList< QList<int> > strobeNotes;
  };
  QList<Instrument> Instruments;
  // fill the combobox for instrument selection
  void FillInstrumentCombo(QComboBox * combo);

protected:
  // read configuration files
  void readConfiguration();
  void readInstruments(const char * path);
  Instrument readInstrument(QXmlStreamReader * xml);
  QList<int> readInstrumentRow(QXmlStreamReader * xml);
  // rebuild the musical scale
  void buildScale(void);
  
  // the frequency of the reference note for scale building
  float referenceFrequency;

public slots:
  void setReferenceFrequency(double frequency);
  
signals:
  void scaleChanged(void);

};

#endif
